home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Quick Edit ƒ
/
Subject Glossary
/
Floating Point
< prev
next >
Wrap
Text File
|
1997-08-20
|
5KB
|
215 lines
(special note: This description of the Mops floating point environment is
incomplete. Please refer to the Mops file floating point and the Apple
Numerics Manual for detail complete information.)
GENERAL
A floating point number (flt) is input by placing a decimal point anywhere in
the number. There is no separate stack for floats, they are accessed via
pointers on the normal stack.
All numbers to be input as floats must contain one decimal point.
The numeric base may be other than decimal when using floating point. Floats
will always be interpretted in base 10 regardless of base. Non-floats (no
decimal point) will be interpretted in the current base.
The general form for a float is as follows:
Sxxx.yyyEszz There can be NO blanks between the components of a float.
S = optional sign of mantissa (+ or - or blank)
xxx.yyy = required mantissa with required decimal (must have xxx or yyy or both)
E = optional exponent delimiter (may be e)
s = optional sign of exponent
zz = optional exponent, must be preceded by E
Note that local variables and named input parameters to be used for floating point
numbers must have their names preceded by %.
\ =========== NUMERIC CONVERSION =============
FLOAT> \ ( flt -- n ) Converts the float to an int, rounds.
>FLOAT \ ( n -- flt ) Converts the int to a float.
FCONV? { addr len -- flt T | -- F }
\ Converts the passed-in ASCII string to
\ floating, if possible. I like this name better
\ than ATOF which Neon had, but change it back if
\ you want to.
\ ========== MEMORY ============
FVALUE flt -- : name Fp analog of value, can use prefix operators.
FCON flt -- : name Fp analog of constant.
\ ========== STACK MANIPULATION ============
FDUP flt -- flt flt
FOVER flt1 flt2 -- flt1 flt2 flt1
F2DUP flt1 flt2 -- flt1 flt2
FDROP flt --
F2DROP flt1 flt2 --
\ ========= Dyadic comparisons ==========
Stack frame for all dyadic comparisons: ( flt1 flt2 -- b )
F>
F<
F≥
F≤
F=
F≠
\ ========= Monadic comparisons ==========
Stack frame for all monadic comparisons: ( flt -- b )
F0=
F0≠
F0≥
F0<
F0≤
F0>
\ =============== Arithmetic operators ==============
\ ( flt1 flt2 -- flt1<op>flt2 ) Result gets stored in flt1's data.
F+
F-
F*
F/
PREFIX OPERATORS Use for fvalues, local fvariables, named input parameters.
-> flt -- : word Gazinta. Stores flt.
++> flt -- : word Adds flt.
--> flt -- : word Subtracts flt.
NEG> -- : word Negates.
*> flt -- : word Multiplies by flt.
/> flt -- : word Divides by flt.
ABS> -- : word Changes to absolute value.
\ ============= Monadic operations ==============
\ FNEGATE and FABS simply operate on the sign bit, so we don't need to call
SANE at all. The SANE manual actually recommends this.
FNEGATE
FABS
SQRT
ROUND ( flt1 -- flt2 ) FloatingPoint floating point
Rounds the given float to the nearest integer by the
rules in effect via SETENV (see below). Of course we still
have a float.
Note that default rounding is via ASTM.
Examples:
hex 1000 setenv decimal \ the default anyway
1.50 round 5 f.r
2.000000>
2.50 round 5 f.r
2.000000
GETENV \ ( -- env )
SETENV \ ( env -- ) default environment is 1000
\ =========== Masks for environment word ===========
hex
\ Rounding
2000 constant RoundUp
4000 constant RoundDown
6000 constant RoundToZero
\ Exception flags
0100 constant Invalid
0200 constant Underflow
0400 constant Overflow
0800 constant Zdivide
1000 constant Inexact
TRUNC ( flt1 -- flt2 ) FloatingPoint floating point
Truncates the fractional portion of the given float. Of course
we still have a float.
\ ===================================
\ FP to/from decimal conversion
\ ===================================
E.R ( flt wid -- ) Prints the floating point number in scientific notation
in a field wid characters wide.
wide
E. ( flt -- ) \ same as 26 e.r
F.R ( flt wid -- ) Prints the floating point number without exponents in a
field wid characters wide.
\ =================================
\ Transcendentals
\ =================================
LN \ Natural log
LOG2 \ Base 2 log
LN1 \ ln(1+x)
LOG21 \ log2(1+x). I don't think LOG21 is a very helpful name (pure
\ computerese), but I guess we're stuck with it.
EXP \ Base e exponential
EXP2 \ Base 2 exponential
EXP1 \ e**x - 1
EXP21 \ 2**x - 1
**N \ ( x n -- x**n ) Integer exponentiation. This wasn't
\ in Neon, but might be useful. Note this operation
\ ignores the high-order 16 bits of n.
F** \ ( x y -- x**y ) General exponentiation - takes 2 floats.
\ Here I think the Neon name was crazy. But we've still
\ got it below for compatibility.
\ Trig functions.
DEG2RAD \ ( deg -- rad ) Converts degrees to radians
RAD2DEG \ ( rad -- deg ) Converts radians to degrees
The following require radians as input.
SIN
COS
TAN
ARCTAN
COT \ ( x -- cot(x) ) Cotangent of x
FRAND \ floating-pt random number routine
\ ======================================
\ Sundry useful constants and operations
\ ======================================
1.0 exp fcon E
10.0 ln fcon LN(10)
PI
UNDEF \ Ditto
1/X
LOG \ ( x -- log(x) ) Log base 10 of x
ANTILOG \ ( x -- antilog(x) ) Antilog ( 10^x ) of x